package com.yu.registrar;

import com.yu.util.CuratorUtil;
import org.apache.curator.framework.CuratorFramework;

import java.net.InetSocketAddress;

/**
 * @PackageName: com.yu.registrar
 * @Description:
 * @Version: v1.0.0
 * @Author: yuweilin
 * @Date: 13:43
 * <p>
 * Modification History:
 * Date         Author          Version            Description
 * ------------------------------------------------------------
 * 2021/1/23      yuweilin         v1.0.0               新建
 */
public class ZKServiceRegistrar implements ServiceRegistrar{
    @Override
    public void registerService(String rpcServiceName, InetSocketAddress inetSocketAddress) {
        String localhost = inetSocketAddress.toString();
        int index = localhost.indexOf("/");
        String servicePath = CuratorUtil.ZK_REGISTRAR_ROOT_PATH + "/" + rpcServiceName + localhost.substring(index).trim();
        CuratorFramework zkClient = CuratorUtil.getZkClient();
        CuratorUtil.createPersistentNode(zkClient,servicePath);
    }
}
